setClass("ScreeDimChooser",contains="MDSDimChooser",
		prototype=prototype(
				.description="Scree plot DimChooser"
		)
)
#methods

setMethod("chooseBest",
		signature=c("ScreeDimChooser","MDSReducer"),
		definition= function(.Object,reducer,...){
			
			#initial computations
			dims <- dim(reducer@.tmpData)
			rows <- dims[1] #objects
			cols <- dims[2] #dimensions
			checkedDims <- min(rows -1,cols)
			
			scores <- unlist(lapply(1:checkedDims,FUN=function(cDim){
								#returns distance matrix in reduced set
								redSetDims <-as.matrix(dist( as.matrix( cmdscale(reducer@.dataDimsMatrix,k=cDim )),method=reducer@.distanceType,p=reducer@.minkowskiParam  ))
								scoreSet(.Object,reducer,redSetDims)
							}))
			#return first above threshold
			mScores <- mean(scores)
			selVec <- scores[which(scores>mScores)]
			return(as.integer(length(selVec)))
		}
)


setMethod("scoreSet",
		signature=c("ScreeDimChooser","MDSReducer"),
		definition= function(.Object,reducer,outSet2Score,...){
			tmp <- reducer@.dataDimsMatrix-outSet2Score 
			score <- sqrt( sum( tmp*tmp )/sum(reducer@.dataDimsMatrix*reducer@.dataDimsMatrix) )
			return(score)
			
		}
) 
